import 'dart:async';
 
import 'package:demo/utils/log_util.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get_connect/http/src/request/request.dart';

import 'package:get/get_connect/http/src/response/response.dart';

import '../../model/api_response.dart';


FutureOr<dynamic> responseInterceptor(Request request, Response response) async {

  if(LogUtil.isLogEnable){
    print(response.body);
  }

  // EasyLoading.dismiss();
  if (response.statusCode != 200) {
    handleErrorStatus(response);
    return;
  }

  var result = ApiResponse.fromJson(response.body);
  if(result.code != 200){
    EasyLoading.showToast('${result.msg}');
    return;
  }

  return response;
}

void handleErrorStatus(Response response) {
  switch (response.statusCode) {
    case 406:
      // final message = ErrorResponse.fromJson(response.body);
      // CommonWidget.toast(message.error);
      break;
    default:
  }

  return;
}
